
<template>
    <div class="file-preview">
        <!-- <docx-preview  :src="props.src" v-if="props.src.indexOf('.docx') != -1" :close="props.close" :scale="props.scale"/> -->
		<docx-preview-cdn  :src="props.src" v-if="props.src.indexOf('.docx') != -1" :close="props.close" :scale="props.scale"/>
        <!-- <pdf-preview  :src="props.src" v-if="props.src.indexOf('.pdf') != -1" :close="props.close" :scale="props.scale"/> -->
		<pdf-preview-cdn :src="props.src" v-if="props.src.indexOf('.pdf') != -1" :close="props.close" :scale="props.scale"/>
        <!-- <xlsx-preview  :src="props.src" v-if="props.src.indexOf('.xlsx') != -1" :close="props.close" :scale="props.scale"/> -->
		<xlsx-preview-cdn  :src="props.src" v-if="props.src.indexOf('.xlsx') != -1" :close="props.close" :scale="props.scale"/>
        <pptx-preview :src="props.src" v-if="props.src.indexOf('.pptx') != -1" :close="props.close" :scale="props.scale"/>
    </div>

</template>

<script setup>
import  XlsxPreview from '@/components/XlsxPreview'
// import  DocxPreview from '@/components/DocxPreview'
import  DocxPreviewCdn from '@/components/DocxPreviewCdn'
// import  PdfPreview from '@/components/PdfPreview'
import  PdfPreviewCdn from '@/components/PdfPreviewCdn'
// import  PptxPreview from '@/components/PptxPreview'
import  XlsxPreviewCdn from '@/components/XlsxPreviewCdn'
import { ElMessage } from 'element-plus'
import { onMounted, reactive } from "vue";


const props = defineProps({
  src: {
    type: String,
    default: ""
  },
  close: {
      type: Function,
      default: () => {

      }
  },
  error: {
      type: Function,
      default: (msg, fileType) => {
          ElMessage({
              message: msg,
              type: 'error',
          });
      }
  },
  // 缩放比例配置
  scale: {
      type: Object,
      default: {
          // 当前比例
          currentScale: 1,
          // 最小比例
          minScale: 0.5,
          // 最大比例
          maxScale: 1.5,
          // 每次缩放的步长
          stepScale: 0.1
      }
  }
});

const supportFileTypes = ['xlsx', 'docx', 'pdf', 'pptx'];

const data = reactive({
    fileExtension: ''
});

onMounted(() => {
    let temp = props.src.split('.');
    if (temp.length > 0) {
        data.fileExtension = temp[temp.length - 1];
        if (!supportFileTypes.includes(data.fileExtension)) {
            props.error(data.fileExtension + '文件格式不支持预览', data.fileExtension);
        }
    }

});

</script>

<style lang="scss" scoped>
.file-preview {

}
</style>
